import { router } from '../../../js/router';
const componentBehavior = require('../../../js/common/ComponentBehavior')

Component({
  behaviors: [componentBehavior],
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  lifetimes: {
    attached() {
      // 在组件实例进入页面节点树时执行
    },
    detached() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  /**
   * 组件的属性列表
   */
  properties: {
    imgDomain: {
      type: String,
      value: ''
    },
    item: {
      type: Object,
      value: {}
    },
    pic: {
      type: String,
      value: '/assets/images/img.png'
    },
    showBigImg:{
      type:Boolean,
      value:false
    },
    gindex: {
      type: Number
    }, //索引
    quantityDigits: {
      type: Number,
      value: 2
    }, //数量显示小数位数
    priceDigits: {
      type: Number,
      value: 2
    }, //价格显示小数位数
    hasSmMarket: {
      type: Boolean,
      value: false
    },
    hasTrash: {
      type: Boolean,
      value: false
    }, //是否显示回收站
    hasNumAct: {
      type: Boolean,
      value: false
    }, //是否显示实际数量
    primaryId: Number, //唯一Id
    isScanty: {
      type: Boolean,
      value: false
    }, //是否开启缺货登记
    isShowInvalid: {
      type: Boolean,
      value: false
    }, //是否显示验证货品状态
    purchasePower: {
      type: Boolean,
      value: true
    }, //是否有购买权限
    showRetailPrice: {
      type: Boolean,
      value: true
    }, //是否显示市场价
    CartName:String,
    FieldDisplayName:Array,
    ClassDisplayField:Object,
    GoodsUnitDisplayMode:{
      value:0,
      type:Number
    },
    Currency:String,
    FrontShowStockDetail:Boolean,
    isLogin:Boolean
  },

  /**
   * 组件的初始数据
   */
  data: {
    baseNum: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**显示多规则 */
    onShowGoodsModal(e) {
      this.triggerEvent("onShowGoodsModal", {
        idx: this.data.gindex
      });
    },
    /**
     * 加入完成后调用，更新界面显示数量
     */
    onAddCartCompleted(e) {
      e = e.detail;
      console.log(e.product,'=======');
      
      this.triggerEvent("onAddCartCompleted", {
        product: e.product,
        idx: this.data.gindex
      });
    },

    toDetail(e) {
      var pagetype = e.currentTarget.dataset.pagetype;
      var linkparam = e.currentTarget.dataset.linkparam;
      var loadcomplate = e.currentTarget.dataset.loadcomplate;
      if (loadcomplate != 1) return;
      if (this.data.isShowInvalid && (((this.data.item.Stock <= 0 || this.data.item.Stock < this.data.item.BuyLowerLimit) && this.data.item.ZeroStockBuy == 0) || this.data.item.Shelved == 0 || !this.data.purchasePower)) {
        return;
      }
      var url = "productDetail";
      if (pagetype == 1 || pagetype == 2) {
        url = "groupDetail";
      }

      this.triggerEvent("toDetail", {
        url: url,
        linkparam
      });
    },
    //弹出缺货登记的层
    onShowScanty(e) {
      this.triggerEvent("onShowScanty", {
        idx: this.data.gindex
      });
    },
    //弹出库存分布的层
    showStockDistribution(e) {
      this.triggerEvent("showStockDistribution", {
        idx: this.data.gindex
      });
    },
    onRemove(e) {
      this.triggerEvent("onRemove", {
        id: this.data.primaryId
      });
    },
    bindLabel(e){
      var id = e.currentTarget.dataset.id;
      router.navigate({
        path:"promotionDetail",
        params:{
          id:id
        }
      })
    },
    bindUnfold(e){
      var that = this;
      var index = e.currentTarget.dataset.index;
      this.triggerEvent("bindUnfold", {
        idx: index
      });
    },
  }
})